import java.awt.Color;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.RoundRectangle2D;

import javax.swing.JFrame;
import javax.swing.JTextArea;

//@author A0097543W
@SuppressWarnings("serial")
public class help extends JFrame {
	
	Font bodyFont = new Font("Calibri", Font.BOLD, 16);
	
	private final static String newline = "\n";
	
	final JTextArea helpText = new JTextArea();
	final JFrame helpFrame = new JFrame();

	public help() {
		
		showHelp(1);
	}

	public void showHelp(int page) {
		
		helpFrame.getContentPane().setBackground(Color.BLACK);
		helpFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		helpFrame.setAlwaysOnTop(true);
		helpFrame.setUndecorated(true);
		helpFrame.setBackground(new Color(0,0,0,180));
		helpFrame.setShape(new RoundRectangle2D.Double(0,0,600,100,15,15));
		helpFrame.setSize(690,150);
		
		positionHelp(helpFrame);

		

		helpText.setBounds(80, 10, 700, 302);
		helpText.setFont(bodyFont);
		helpText.setBackground(new Color(0,0,0,0));
		helpText.setForeground(Color.WHITE);
		helpText.setEditable(false);

		if(page == 1) {
			display1();
		}else if(page == 2) {
			display2();
		}

		
		
		helpFrame.getContentPane().setLayout(null);
		helpFrame.getContentPane().add(helpText);
		helpFrame.setVisible(true);

		class TriggerOnKeyPress implements KeyListener {

			public void keyPressed(KeyEvent keyPressed) {

//				helpText.requestFocus();

				int keyCode = keyPressed.getKeyCode();

				if(keyCode == KeyEvent.VK_F1) {
					helpFrame.setVisible(false);
				} else if(keyCode == KeyEvent.VK_RIGHT) {			//hotkey for next page of help
					helpFrame.dispose();
					showHelp(2);
					//display2();
					
				} else if(keyCode == KeyEvent.VK_LEFT) {			//hotkey for next page of help
					helpFrame.dispose();
					showHelp(1);
					
				}

			}

			public void keyReleased(KeyEvent e) {}
			public void keyTyped(KeyEvent e) {}

		}
		
		TriggerOnKeyPress triggerOnKeyPress = new TriggerOnKeyPress();
		
		helpFrame.addKeyListener(triggerOnKeyPress);
		helpText.addKeyListener(triggerOnKeyPress);
		
		
		
	}

	public void display1() {
		helpText.setText(null);
//		helpText.append("KeyBoard Hotkeys" + newline);
		helpText.append("F1 \t \t Toggle Help" + newline);
		helpText.append("F2 \t \t Toggle View Mode" + newline);
		helpText.append("Ctrl + 1 \t \t All Task" + newline);
		helpText.append("Ctrl + 2 \t \t Completed Tasks" + newline);
		helpText.append("Ctrl + 3 \t \t Outstanding Tasks" + newline);
		helpText.append("Ctrl + z \t \t Undo last command" + newline);
		helpText.append("\t \t \t \t \t        >>>");
	}
	
	public void display2() {
		helpText.setText(null);
		helpText.append("\"add <task>\" \t \t \t to add a new task" + newline);
		helpText.append("\"del <task number>\" \t \t to delete a specific task" + newline);
		helpText.append("\"edit <task numer> /to <new description>\" \t to edit a specific task" + newline);
		helpText.append("\"search <keyword>\" \t \t to search for a specific task" + newline);
		helpText.append("\"mark <task number>\" \t \t to mark a task completed" + newline);
		helpText.append("\"unmark <task number>\" \t \t to mark a task incompleted" + newline);
		helpText.append("<<<");
	}
	

	//setting the position of the help
	public void positionHelp(final JFrame help) {
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
        Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
        int x = (int) rect.getMaxX() - help.getWidth();
        int y = (int) rect.getMaxY() - help.getHeight();
        help.setLocation(x - 10, y-335);
	}
	
	
}


